package test {

import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.utils.*;

import com.whirled.avrg.*;
import com.whirled.net.*;

import aduros.net.*;
import aduros.util.*;

/** The main tic-tac-toe sprite. */
public class libaduros extends Sprite
{
    /**
     * Creates a new tic tac toe sprite and connects to the whirled GameControl.
     */
    public function libaduros ()
    {
        _ctrl = new AVRGameControl(this);
        _caller = new RemoteProxy(_ctrl.agent, null);

        var button :Sprite = new Sprite();
        button.graphics.beginFill(0x00ff00);
        button.graphics.drawRect(0, 0, 50, 50);
        button.graphics.endFill();

        button.addEventListener(MouseEvent.CLICK, function (... _) :void {
//            var data :Data = new Data();
//            data.number = 42;
//            data.string = "foobarz";
//            //_caller.sayHello(data);
            var ba :ByteArray = new ByteArray();
            ba.writeInt(666);
            _caller.oneArg(ba);
        });

        _ctrl.game.addEventListener(MessageReceivedEvent.MESSAGE_RECEIVED, function (event :MessageReceivedEvent) :void {
            _ctrl.local.feedback("Event: name = " + event.name + ", value = " + event.value);
        });

        addChild(button);

        var divide :Function = function (a :Number, b :Number) :Number { return a / b };
        trace(divide(10, 2));

        var divideByTwo :Function = F.partial(divide, F._, 2);
        trace(divideByTwo(10)); // 5
        trace(divideByTwo(8)); // 4
        trace(divideByTwo(542)); // 271

        var greet :Function = F.partial(trace, "hello");
        greet("Joe"); // Prints "hello Joe"
        greet("Bruno"); // Prints "hello Bruno"
    }

    /** The connection to the whirled game server. */
    protected var _ctrl :AVRGameControl;
    protected var _caller :RemoteProxy;
}

}
